use crate::src::src::set::{set_union, set_register_free_function, set_to_array, set_intersection, set_remove, set_free, set_num_entries, set_iter_has_more, set_query, set_insert, set_iterate, set_new, set_iter_next};
use crate::src::test::alloc_testing::{alloc_test_strdup, alloc_test_get_allocated, alloc_test_set_limit, alloc_test_malloc, alloc_test_free};
use crate::src::test::framework::{run_tests};
use crate::src::src::hash_pointer::{pointer_hash};
use crate::src::src::compare_string::{string_equal};
use crate::src::src::compare_pointer::{pointer_equal};
use crate::src::src::hash_int::{int_hash};
use crate::src::src::hash_string::{string_hash};
use crate::src::src::compare_int::{int_equal};
use crate::src::struct_and_type::{Set, SetHashFunc, SetValue, size_t, SetFreeFunc, _Set, _SetEntry, SetEqualFunc, _SetIterator, UnitTestFunction, SetEntry, SetIterator};
use ::libc;
extern "C" {
    
    
    fn sprintf(_: *mut libc::c_char, _: *const libc::c_char, _: ...) -> libc::c_int;
    fn atoi(__nptr: *const libc::c_char) -> libc::c_int;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
#[no_mangle]
pub static mut allocated_values_test_set: libc::c_int = 0;
#[no_mangle]
pub unsafe extern "C" fn generate_set() -> *mut Set {
    let mut set: *mut Set = 0 as *mut Set;
    let mut buf: [libc::c_char; 10] = [0; 10];
    let mut i: libc::c_uint = 0;
    let mut value: *mut libc::c_char = 0 as *mut libc::c_char;
    set = set_new(
        Some(string_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            string_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int as libc::c_uint;
    while i < 10000 as libc::c_int as libc::c_uint {
        sprintf(buf.as_mut_ptr(), b"%i\0" as *const u8 as *const libc::c_char, i);
        value = alloc_test_strdup(buf.as_mut_ptr());
        set_insert(set, value as SetValue);
        assert!(set_num_entries(set) == i.wrapping_add(1 as libc::c_int as libc::c_uint));
        i = i.wrapping_add(1);
        i;
    }
    set_register_free_function(
        set,
        Some(alloc_test_free as unsafe extern "C" fn(*mut libc::c_void) -> ()),
    );
    return set;
}
#[no_mangle]
pub unsafe extern "C" fn test_set_new_free() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut i: libc::c_int = 0;
    let mut value: *mut libc::c_int = 0 as *mut libc::c_int;
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    set_register_free_function(
        set,
        Some(alloc_test_free as unsafe extern "C" fn(*mut libc::c_void) -> ()),
    );
    assert!(!set.is_null());
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        value = alloc_test_malloc(::core::mem::size_of::<libc::c_int>() as libc::c_ulong)
            as *mut libc::c_int;
        *value = i;
        set_insert(set, value as SetValue);
        i += 1;
        i;
    }
    set_free(set);
    alloc_test_set_limit(0 as libc::c_int);
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    assert!(set.is_null());
    alloc_test_set_limit(1 as libc::c_int);
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    assert!(set.is_null());
    assert!(alloc_test_get_allocated() == 0 as libc::c_int as libc::c_ulong);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_insert() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut numbers1: [libc::c_int; 6] = [
        1 as libc::c_int,
        2 as libc::c_int,
        3 as libc::c_int,
        4 as libc::c_int,
        5 as libc::c_int,
        6 as libc::c_int,
    ];
    let mut numbers2: [libc::c_int; 6] = [
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
        8 as libc::c_int,
        9 as libc::c_int,
        10 as libc::c_int,
    ];
    let mut i: libc::c_int = 0;
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 6 as libc::c_int {
        set_insert(
            set,
            &mut *numbers1.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as SetValue,
        );
        i += 1;
        i;
    }
    i = 0 as libc::c_int;
    while i < 6 as libc::c_int {
        set_insert(
            set,
            &mut *numbers2.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as SetValue,
        );
        i += 1;
        i;
    }
    assert!(set_num_entries(set) == 10 as libc::c_int as libc::c_uint);
    set_free(set);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_query() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut buf: [libc::c_char; 10] = [0; 10];
    let mut i: libc::c_int = 0;
    set = generate_set();
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        sprintf(buf.as_mut_ptr(), b"%i\0" as *const u8 as *const libc::c_char, i);
        assert!(set_query(set, buf.as_mut_ptr() as SetValue) != 0 as libc::c_int);
        i += 1;
        i;
    }
    assert!(set_query(set, b"-1\0" as *const u8 as *const libc::c_char as SetValue)
        == 0 as libc::c_int);
    assert!(set_query(set, b"100001\0" as *const u8 as *const libc::c_char as SetValue)
        == 0 as libc::c_int);
    set_free(set);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_remove() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut buf: [libc::c_char; 10] = [0; 10];
    let mut i: libc::c_int = 0;
    let mut num_entries: libc::c_uint = 0;
    set = generate_set();
    num_entries = set_num_entries(set);
    assert!(num_entries == 10000 as libc::c_int as libc::c_uint);
    i = 4000 as libc::c_int;
    while i < 6000 as libc::c_int {
        sprintf(buf.as_mut_ptr(), b"%i\0" as *const u8 as *const libc::c_char, i);
        assert!(set_query(set, buf.as_mut_ptr() as SetValue) != 0 as libc::c_int);
        assert!(set_remove(set, buf.as_mut_ptr() as SetValue) != 0 as libc::c_int);
        assert!(set_num_entries(set)
            == num_entries.wrapping_sub(1 as libc::c_int as libc::c_uint));
        assert!(set_query(set, buf.as_mut_ptr() as SetValue) == 0 as libc::c_int);
        num_entries = num_entries.wrapping_sub(1);
        num_entries;
        i += 1;
        i;
    }
    i = -(1000 as libc::c_int);
    while i < -(500 as libc::c_int) {
        sprintf(buf.as_mut_ptr(), b"%i\0" as *const u8 as *const libc::c_char, i);
        assert!(set_remove(set, buf.as_mut_ptr() as SetValue) == 0 as libc::c_int);
        assert!(set_num_entries(set) == num_entries);
        i += 1;
        i;
    }
    i = 50000 as libc::c_int;
    while i < 51000 as libc::c_int {
        sprintf(buf.as_mut_ptr(), b"%i\0" as *const u8 as *const libc::c_char, i);
        assert!(set_remove(set, buf.as_mut_ptr() as SetValue) == 0 as libc::c_int);
        assert!(set_num_entries(set) == num_entries);
        i += 1;
        i;
    }
    set_free(set);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_union() {
    let mut numbers1: [libc::c_int; 7] = [
        1 as libc::c_int,
        2 as libc::c_int,
        3 as libc::c_int,
        4 as libc::c_int,
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
    ];
    let mut numbers2: [libc::c_int; 7] = [
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
        8 as libc::c_int,
        9 as libc::c_int,
        10 as libc::c_int,
        11 as libc::c_int,
    ];
    let mut result: [libc::c_int; 11] = [
        1 as libc::c_int,
        2 as libc::c_int,
        3 as libc::c_int,
        4 as libc::c_int,
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
        8 as libc::c_int,
        9 as libc::c_int,
        10 as libc::c_int,
        11 as libc::c_int,
    ];
    let mut i: libc::c_int = 0;
    let mut set1: *mut Set = 0 as *mut Set;
    let mut set2: *mut Set = 0 as *mut Set;
    let mut result_set: *mut Set = 0 as *mut Set;
    let mut allocated: size_t = 0;
    set1 = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 7 as libc::c_int {
        set_insert(
            set1,
            &mut *numbers1.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as SetValue,
        );
        i += 1;
        i;
    }
    set2 = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 7 as libc::c_int {
        set_insert(
            set2,
            &mut *numbers2.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as SetValue,
        );
        i += 1;
        i;
    }
    result_set = set_union(set1, set2);
    assert!(set_num_entries(result_set) == 11 as libc::c_int as libc::c_uint);
    i = 0 as libc::c_int;
    while i < 11 as libc::c_int {
        assert!(set_query(
            result_set,
            &mut *result.as_mut_ptr().offset(i as isize) as *mut libc::c_int as SetValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    set_free(result_set);
    alloc_test_set_limit(0 as libc::c_int);
    assert!((set_union(set1, set2)).is_null());
    alloc_test_set_limit(2 as libc::c_int + 2 as libc::c_int);
    allocated = alloc_test_get_allocated();
    assert!((set_union(set1, set2)).is_null());
    assert!(alloc_test_get_allocated() == allocated);
    alloc_test_set_limit(2 as libc::c_int + 7 as libc::c_int + 2 as libc::c_int);
    allocated = alloc_test_get_allocated();
    assert!((set_union(set1, set2)).is_null());
    assert!(alloc_test_get_allocated() == allocated);
    set_free(set1);
    set_free(set2);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_intersection() {
    let mut numbers1: [libc::c_int; 7] = [
        1 as libc::c_int,
        2 as libc::c_int,
        3 as libc::c_int,
        4 as libc::c_int,
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
    ];
    let mut numbers2: [libc::c_int; 7] = [
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
        8 as libc::c_int,
        9 as libc::c_int,
        10 as libc::c_int,
        11 as libc::c_int,
    ];
    let mut result: [libc::c_int; 3] = [
        5 as libc::c_int,
        6 as libc::c_int,
        7 as libc::c_int,
    ];
    let mut i: libc::c_int = 0;
    let mut set1: *mut Set = 0 as *mut Set;
    let mut set2: *mut Set = 0 as *mut Set;
    let mut result_set: *mut Set = 0 as *mut Set;
    let mut allocated: size_t = 0;
    set1 = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 7 as libc::c_int {
        set_insert(
            set1,
            &mut *numbers1.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as SetValue,
        );
        i += 1;
        i;
    }
    set2 = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 7 as libc::c_int {
        set_insert(
            set2,
            &mut *numbers2.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as SetValue,
        );
        i += 1;
        i;
    }
    result_set = set_intersection(set1, set2);
    assert!(set_num_entries(result_set) == 3 as libc::c_int as libc::c_uint);
    i = 0 as libc::c_int;
    while i < 3 as libc::c_int {
        assert!(set_query(
            result_set,
            &mut *result.as_mut_ptr().offset(i as isize) as *mut libc::c_int as SetValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    alloc_test_set_limit(0 as libc::c_int);
    assert!((set_intersection(set1, set2)).is_null());
    alloc_test_set_limit(2 as libc::c_int + 2 as libc::c_int);
    allocated = alloc_test_get_allocated();
    assert!((set_intersection(set1, set2)).is_null());
    assert!(alloc_test_get_allocated() == allocated);
    set_free(set1);
    set_free(set2);
    set_free(result_set);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_to_array() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut values: [libc::c_int; 100] = [0; 100];
    let mut array: *mut *mut libc::c_int = 0 as *mut *mut libc::c_int;
    let mut i: libc::c_int = 0;
    set = set_new(
        Some(pointer_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            pointer_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 100 as libc::c_int {
        values[i as usize] = 1 as libc::c_int;
        set_insert(
            set,
            &mut *values.as_mut_ptr().offset(i as isize) as *mut libc::c_int as SetValue,
        );
        i += 1;
        i;
    }
    array = set_to_array(set) as *mut *mut libc::c_int;
    i = 0 as libc::c_int;
    while i < 100 as libc::c_int {
        assert!(**array.offset(i as isize) == 1 as libc::c_int);
        **array.offset(i as isize) = 0 as libc::c_int;
        i += 1;
        i;
    }
    alloc_test_set_limit(0 as libc::c_int);
    assert!((set_to_array(set)).is_null());
    alloc_test_free(array as *mut libc::c_void);
    set_free(set);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_iterating() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut iterator: SetIterator = SetIterator {
        set: 0 as *mut Set,
        next_entry: 0 as *mut SetEntry,
        next_chain: 0,
    };
    let mut count: libc::c_int = 0;
    set = generate_set();
    count = 0 as libc::c_int;
    set_iterate(set, &mut iterator);
    while set_iter_has_more(&mut iterator) != 0 {
        set_iter_next(&mut iterator);
        count += 1;
        count;
    }
    assert!((set_iter_next(&mut iterator)).is_null());
    assert!(count == 10000 as libc::c_int);
    set_free(set);
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    set_iterate(set, &mut iterator);
    assert!(set_iter_has_more(&mut iterator) == 0 as libc::c_int);
    set_free(set);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_iterating_remove() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut iterator: SetIterator = SetIterator {
        set: 0 as *mut Set,
        next_entry: 0 as *mut SetEntry,
        next_chain: 0,
    };
    let mut count: libc::c_int = 0;
    let mut removed: libc::c_uint = 0;
    let mut value: *mut libc::c_char = 0 as *mut libc::c_char;
    set = generate_set();
    count = 0 as libc::c_int;
    removed = 0 as libc::c_int as libc::c_uint;
    set_iterate(set, &mut iterator);
    while set_iter_has_more(&mut iterator) != 0 {
        value = set_iter_next(&mut iterator) as *mut libc::c_char;
        if atoi(value) % 100 as libc::c_int == 0 as libc::c_int {
            set_remove(set, value as SetValue);
            removed = removed.wrapping_add(1);
            removed;
        }
        count += 1;
        count;
    }
    assert!(count == 10000 as libc::c_int);
    assert!(removed == 100 as libc::c_int as libc::c_uint);
    assert!(set_num_entries(set)
        == (10000 as libc::c_int as libc::c_uint).wrapping_sub(removed));
    set_free(set);
}
#[no_mangle]
pub unsafe extern "C" fn new_value_test_set(mut value: libc::c_int) -> *mut libc::c_int {
    let mut result: *mut libc::c_int = 0 as *mut libc::c_int;
    result = alloc_test_malloc(::core::mem::size_of::<libc::c_int>() as libc::c_ulong)
        as *mut libc::c_int;
    *result = value;
    allocated_values_test_set += 1;
    allocated_values_test_set;
    return result;
}
#[no_mangle]
pub unsafe extern "C" fn free_value_test_set(mut value: *mut libc::c_void) {
    alloc_test_free(value);
    allocated_values_test_set -= 1;
    allocated_values_test_set;
}
#[no_mangle]
pub unsafe extern "C" fn test_set_free_function() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut i: libc::c_int = 0;
    let mut value: *mut libc::c_int = 0 as *mut libc::c_int;
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    set_register_free_function(
        set,
        Some(free_value_test_set as unsafe extern "C" fn(*mut libc::c_void) -> ()),
    );
    allocated_values_test_set = 0 as libc::c_int;
    i = 0 as libc::c_int;
    while i < 1000 as libc::c_int {
        value = new_value_test_set(i);
        set_insert(set, value as SetValue);
        i += 1;
        i;
    }
    assert!(allocated_values_test_set == 1000 as libc::c_int);
    i = 500 as libc::c_int;
    set_remove(set, &mut i as *mut libc::c_int as SetValue);
    assert!(allocated_values_test_set == 999 as libc::c_int);
    set_free(set);
    assert!(allocated_values_test_set == 0 as libc::c_int);
}
#[no_mangle]
pub unsafe extern "C" fn test_set_out_of_memory() {
    let mut set: *mut Set = 0 as *mut Set;
    let mut values: [libc::c_int; 66] = [0; 66];
    let mut i: libc::c_uint = 0;
    set = set_new(
        Some(int_hash as unsafe extern "C" fn(*mut libc::c_void) -> libc::c_uint),
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    alloc_test_set_limit(0 as libc::c_int);
    values[0 as libc::c_int as usize] = 0 as libc::c_int;
    assert!(set_insert(
        set,
        &mut *values.as_mut_ptr().offset(0 as libc::c_int as isize) as *mut libc::c_int
            as SetValue,
    ) == 0 as libc::c_int);
    assert!(set_num_entries(set) == 0 as libc::c_int as libc::c_uint);
    alloc_test_set_limit(-(1 as libc::c_int));
    i = 0 as libc::c_int as libc::c_uint;
    while i < 65 as libc::c_int as libc::c_uint {
        values[i as usize] = i as libc::c_int;
        assert!(set_insert(
            set,
            &mut *values.as_mut_ptr().offset(i as isize) as *mut libc::c_int as SetValue,
        ) != 0 as libc::c_int);
        assert!(set_num_entries(set) == i.wrapping_add(1 as libc::c_int as libc::c_uint));
        i = i.wrapping_add(1);
        i;
    }
    assert!(set_num_entries(set) == 65 as libc::c_int as libc::c_uint);
    alloc_test_set_limit(0 as libc::c_int);
    values[65 as libc::c_int as usize] = 65 as libc::c_int;
    assert!(set_insert(
        set,
        &mut *values.as_mut_ptr().offset(65 as libc::c_int as isize) as *mut libc::c_int
            as SetValue,
    ) == 0 as libc::c_int);
    assert!(set_num_entries(set) == 65 as libc::c_int as libc::c_uint);
    set_free(set);
}
static mut tests_test_set: [UnitTestFunction; 12] = unsafe {
    [
        Some(test_set_new_free as unsafe extern "C" fn() -> ()),
        Some(test_set_insert as unsafe extern "C" fn() -> ()),
        Some(test_set_query as unsafe extern "C" fn() -> ()),
        Some(test_set_remove as unsafe extern "C" fn() -> ()),
        Some(test_set_intersection as unsafe extern "C" fn() -> ()),
        Some(test_set_union as unsafe extern "C" fn() -> ()),
        Some(test_set_iterating as unsafe extern "C" fn() -> ()),
        Some(test_set_iterating_remove as unsafe extern "C" fn() -> ()),
        Some(test_set_to_array as unsafe extern "C" fn() -> ()),
        Some(test_set_free_function as unsafe extern "C" fn() -> ()),
        Some(test_set_out_of_memory as unsafe extern "C" fn() -> ()),
        None,
    ]
};
unsafe fn main_0_test_set(
    mut argc: libc::c_int,
    mut argv: *mut *mut libc::c_char,
) -> libc::c_int {
    run_tests(tests_test_set.as_mut_ptr());
    return 0 as libc::c_int;
}
pub fn main_test_set() {
    let mut args: Vec::<*mut libc::c_char> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    unsafe {
        ::std::process::exit(
            main_0_test_set(
                (args.len() - 1) as libc::c_int,
                args.as_mut_ptr() as *mut *mut libc::c_char,
            ) as i32,
        )
    }
}
